package com.lxj.fast_android_demo.ui;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.lxj.fast_android_demo.R;
import com.lxj.fast_android_demo.ui.adapter.TableAdapter;

public class TableAc extends Activity {
	private ListView lvList;
	private TextView tvHead1;
	private TextView tvHead2;
	private TextView tvHead3;
	private TextView tvHead4;
	private TextView tvHead5;
	private TextView tvHead6;
	private TextView tvHead7;
	private ListAdapter adapter;
	private ArrayList<HashMap<String, Object>> dataList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.table_ac);

		lvList = (ListView) findViewById(R.id.lvList);
		tvHead1 = (TextView) findViewById(R.id.tvHead1);
		tvHead2 = (TextView) findViewById(R.id.tvHead2);
		tvHead3 = (TextView) findViewById(R.id.tvHead3);
		tvHead4 = (TextView) findViewById(R.id.tvHead4);
		tvHead5 = (TextView) findViewById(R.id.tvHead5);
		tvHead6 = (TextView) findViewById(R.id.tvHead6);
		tvHead7 = (TextView) findViewById(R.id.tvHead7);
		tvHead1.setText("姓名");
		tvHead2.setText("年龄");
		tvHead3.setText("性别");
		tvHead4.setText("备注");
		tvHead5.setText("factor1");
		tvHead6.setText("factor2");
		tvHead7.setText("result");

		dataList = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("empName", "梁香菊");
		map.put("empAge", 30);
		map.put("empGender", 0);
		map.put("memo", "aaa");
		map.put("factor1", 1);
		map.put("factor2", 11);
		map.put("result", 0.0);
		dataList.add(map);
		map = new HashMap<String, Object>();
		map.put("empName", "付海峰");
		map.put("empAge", 22);
		map.put("empGender", 1);
		map.put("memo", "bbb");
		map.put("factor1", 2);
		map.put("factor2", 22);
		map.put("result", 0.0);
		dataList.add(map);
		map = new HashMap<String, Object>();
		map.put("empName", "颜舒波");
		map.put("empAge", 28);
		map.put("empGender", 1);
		map.put("memo", "ccc");
		map.put("factor1", 3);
		map.put("factor2", 33);
		map.put("result", 0.0);
		dataList.add(map);
		map = new HashMap<String, Object>();
		map.put("empName", "王爽");
		map.put("empAge", 23);
		map.put("empGender", 0);
		map.put("memo", "ddd");
		map.put("factor1", 4);
		map.put("factor2", 44);
		map.put("result", 0.0);
		dataList.add(map);
		map = new HashMap<String, Object>();
		map.put("empName", "韩晶");
		map.put("empAge", 31);
		map.put("empGender", 1);
		map.put("memo", "eee");
		map.put("factor1", 5);
		map.put("factor2", 55);
		map.put("result", 0.0);
		dataList.add(map);
		map = new HashMap<String, Object>();
		map.put("empName", "申莎莎");
		map.put("empAge", 24);
		map.put("empGender", 0);
		map.put("memo", "fff");
		map.put("factor1", 6);
		map.put("factor2", 66);
		map.put("result", 0.0);
		dataList.add(map);
		map = new HashMap<String, Object>();
		map.put("empName", "陈杰");
		map.put("empAge", 25);
		map.put("empGender", 0);
		map.put("memo", "这个人很懒，没有留memo");
		map.put("factor1", 0.0);
		map.put("factor2", 0.0);
		map.put("result", 0.0);
		dataList.add(map);

		adapter = new TableAdapter(dataList);
		lvList.setAdapter(adapter);

		lvList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				FormAc.lunch(TableAc.this, dataList.get(arg2));
			}
		});
	}
}
